﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;

namespace libCouchStorage
{
    [Serializable()]
    class CouchDBConfig
    {
        [XmlElement("ServerName")]
        public string Server { get; set; }
        [XmlElement("Port")]
        public int Port { get; set; }
        [XmlElement("UserName")]
        public string User { get; set; }
        [XmlElement("Password")]
        public string Pass { get; set; }
        [XmlElement("Database")]
        public string Database { get; set; }

        public static CouchDBConfig load(string fileName)
        {
            XmlSerializer xSer = new XmlSerializer(typeof(CouchDBConfig));
            TextReader reader = new StringReader(fileName);
            return (CouchDBConfig)xSer.Deserialize(reader);
        }

        public void safe(string fileName)
        {
            XmlSerializer xSer = new XmlSerializer(typeof(CouchDBConfig));
            TextWriter writer = new StreamWriter(fileName);
            xSer.Serialize(writer, this);
        }
    }
}
